package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysAssetBorrowApplyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysAssetBorrowApply;
import com.ruoyi.system.service.ISysAssetBorrowApplyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产借出申请Controller
 * 
 * @author sxy
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/apply")
public class SysAssetBorrowApplyController extends BaseController
{
    @Autowired
    private ISysAssetBorrowApplyService sysAssetBorrowApplyService;

    /**
     * 查询资产借出申请列表
     */
    @RequiresPermissions("system:apply:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAssetBorrowApply sysAssetBorrowApply)
    {
        startPage();
        List<SysAssetBorrowApplyVo> list = sysAssetBorrowApplyService.selectSysAssetBorrowApplyList(sysAssetBorrowApply);
        return getDataTable(list);
    }

    /**
     * 导出资产借出申请列表
     */
    @RequiresPermissions("system:apply:export")
    @Log(title = "资产借出申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAssetBorrowApply sysAssetBorrowApply)
    {
        List<SysAssetBorrowApplyVo> list = sysAssetBorrowApplyService.selectSysAssetBorrowApplyList(sysAssetBorrowApply);
        ExcelUtil<SysAssetBorrowApplyVo> util = new ExcelUtil<SysAssetBorrowApplyVo>(SysAssetBorrowApplyVo.class);
        util.exportExcel(response, list, "资产借出申请数据");
    }

    /**
     * 获取资产借出申请详细信息
     */
    @RequiresPermissions("system:apply:query")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(sysAssetBorrowApplyService.selectSysAssetBorrowApplyByApplyId(applyId));
    }

    /**
     * 新增资产借出申请
     */
    @RequiresPermissions("system:apply:add")
    @Log(title = "资产借出申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAssetBorrowApply sysAssetBorrowApply)
    {
        return toAjax(sysAssetBorrowApplyService.insertSysAssetBorrowApply(sysAssetBorrowApply));
    }

    /**
     * 修改资产借出申请
     */
    @RequiresPermissions("system:apply:edit")
    @Log(title = "资产借出申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAssetBorrowApply sysAssetBorrowApply)
    {
        return toAjax(sysAssetBorrowApplyService.updateSysAssetBorrowApply(sysAssetBorrowApply));
    }

    /**
     * 删除资产借出申请
     */
    @RequiresPermissions("system:apply:remove")
    @Log(title = "资产借出申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(sysAssetBorrowApplyService.deleteSysAssetBorrowApplyByApplyIds(applyIds));
    }
}
